package com.example.messages.utils;

import lombok.Data;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;

@Component
@Data
public class Result implements Serializable {
    private int code; // 200是正常，非200表示异常
    private String msg;
    private Object data;

    public static Result succeed() {
        return succeed(200,"验证码发送成功",null);
    }

    public static Result succeed(int code,String msg,Object data) {
        Result result=new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }


    public static Result fail_exception() {
        return fail(400, "验证码发送异常", null);
    }

    public static Result fail_exist() {
        return fail(400, "该手机号已经发送过验证码", null);
    }

    public static Result fail(int code, String msg, Object data) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

}
